import { useRouter } from "vue-router";
import request from "./request";
import { UrlPrefix } from "../config/const";
export const utils: Utils = {
    async getClipboardData() {
        // const el = document.createElement('textarea');
        // document.body.appendChild(el);
        // el.focus();
        // document.execCommand('paste');
        // const clipboardData = el.value || (window as any).clipboardData?.getData('Text') || await navigator?.clipboard?.readText();
        // document.body.removeChild(el);
        // console.log('getClipboardData text', clipboardData);

        // const clipboardInstance = new ClipboardItem(undefined, null)
        // console.log('clipboardInstance',clipboardInstance);

        const clipboardData = ''
        // clipboardInstance.getData('text/plain')
        return clipboardData;
    },
    goBack(router: any) {
        router.go(-1)
    },
    getJson(URL: string) {
        // const res: CommonType.ResDataType<any> = await axios.get(URL)
        // https://oss.quliye.com/ce/staging/IQ/DETAILS.json
        // const [_, postUrl] = URL.split('https://oss.quliye.com')
        // return request.get(`${UrlPrefix.json}${postUrl}`)
        return fetch(URL as string).then(res => res.json())
    },
    // 获取URI参数对象
    queryParse(url) {
        url = url.replace('/#', '');
        return Array.from(new URL(url).searchParams).reduce((cur: { [k: string]: string }, [key, value]) => {
            cur[key] = value;
            return cur;
        }, {});
    },
}